<script>
import { Search, Plus } from '@element-plus/icons-vue'
import { selectAdminList } from '@/api/admin/admin.js'
import AddManagerDialog from './dialog/AdminManager/AddManagerDialog.vue'
import EditManagerDialog from './dialog/AdminManager/EditManagerDialog.vue'

export default {
  components: {
    Search,
    Plus,
    AddManagerDialog,
    EditManagerDialog,
  },
  data() {
    return {
      params: {},
      list: [],
      isShowAdd: false,
      isShowEdit: false,
    }
  },
  methods: {
    async openEditDailog(row) {
      this.$refs.editDialog.setDefaultForm({ ...row })
      this.isShowEdit = true
    },
    async loadAdminList() {
      const data = await selectAdminList(this.params)
      this.list = data
    },
  },
  created() {
    this.loadAdminList()
  },
}
</script>

<template>
  <div class="title">
    <el-button type="success" size="small" @click="isShowAdd = true">
      <el-icon><Plus></Plus></el-icon>
      <span>新增</span>
    </el-button>
  </div>
  <el-table border :data="list">
    <el-table-column label="序号" type="index" width="60px"></el-table-column>
    <el-table-column label="管理员编号" prop="admin_id"></el-table-column>
    <el-table-column label="系名" prop="admin_username"></el-table-column>
    <el-table-column label="角色" #default="{ row }">
      <el-tag size="small" effect="dark">{{ row.role_name }}</el-tag>
    </el-table-column>
    <el-table-column label="权限数量" #default="{ row }">
      <el-tag size="small" effect="dark" type="danger">{{ row.rights_count }}</el-tag>
    </el-table-column>
    <el-table-column label="操作" width="120" #default="{ row }">
      <el-button type="primary" size="small" link @click="openEditDailog(row)">编辑</el-button>
      <el-popconfirm title="是否删除当前课程" #reference>
        <el-button type="danger" size="small" link>删除</el-button>
      </el-popconfirm>
    </el-table-column>
  </el-table>
  <AddManagerDialog v-model="isShowAdd" @resetData="loadAdminList"></AddManagerDialog>
  <EditManagerDialog
    v-model="isShowEdit"
    @resetData="loadAdminList"
    ref="editDialog"
  ></EditManagerDialog>
</template>

<style scoped>
.el-table {
  margin-top: 16px;
}
</style>
